package com.groupa.project1.swing;

import java.util.Properties;
import com.groupa.project1.chat.InstantMessageClass;
import com.groupa.project1.database.DBManagerClass;
import com.groupa.project1.database.interfaces.DBManager;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import com.groupa.project1.chat.ContentClass;
import com.groupa.project1.chat.ToolsClass;
import com.groupa.project1.database.DBActionClass;
import com.groupa.project1.database.PhotoClass;
import com.sun.media.jai.widget.DisplayJAI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.image.ByteLookupTable;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.awt.image.LookupOp;
import java.awt.image.LookupTable;
import java.awt.image.ShortLookupTable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collection;
import javax.imageio.ImageIO;
import javax.media.jai.KernelJAI;
import javax.swing.JButton;
import javax.swing.border.TitledBorder;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.XUpdateQueryService;



class DisplayPanel1 extends JPanel {
  Image displayImage,output;
  String path;
  BufferedImage bi, biSrc, biDest, bi2;
  
  Graphics2D big,big2;

  LookupTable lookupTable;
  
  KernelJAI kernel;
  
  float[] elements = { 0.0f, -1.0f, 0.0f,
                         -1.0f,  5.f, -1.0f,
                         0.0f, -1.0f,  0.0f};

  DisplayPanel1(String path) {
    this.path = path;
    setBackground(Color.black); // panel background color
    loadImage();
    setSize(displayImage.getWidth(this),displayImage.getWidth(this)); // panel
    createBufferedImage();
    //createBufferedImage2();
    bi2=biSrc;
  }
   public BufferedImage getBi() {
        return bi;
  }
   
  public void loadImage() {
    displayImage = Toolkit.getDefaultToolkit().getImage(path);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(displayImage, 1);
    try {
      mt.waitForAll();
    } catch (Exception e) {
      System.out.println("Exception while loading.");
    }

    if (displayImage.getWidth(this) == -1) {
      System.out.println("No jpg file");
      System.exit(0);
    }
  }

  public void createBufferedImage() {
    bi = new BufferedImage(displayImage.getWidth(null), displayImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    big = bi.createGraphics();
    big.drawImage(displayImage, 0, 0, this);
    biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB);
    big2 = biSrc.createGraphics();
    big2.drawImage(displayImage, 0, 0, this);
    biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB);
  }
  /*public void createBufferedImage2() {
    biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB);
    big2 = biSrc.createGraphics();
    big2.drawImage(displayImage, 0, 0, this);
    biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB);
  }*/

  public void blurring(){            
                BoxBlurFilter b = new BoxBlurFilter();
                b.filter(bi, bi);
  }
  
   public void sharpen() {
    float data[] = { -1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f, -1.0f };
    Kernel kernel = new Kernel(3, 3, data);
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    convolve.filter(biSrc, biDest);
    bi = biDest;
  }

  /*public void blur() {
    float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f };
    Kernel kernel = new Kernel(3, 3, data);
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    convolve.filter(bi, bi);
    //bi = biDest;
  }*/

  public void edgeDetect() {
    float data[] = { 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f, -1.0f };
    Kernel kernel = new Kernel(3, 3, data);
    ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    convolve.filter(biSrc, biDest);
    bi = biDest;
  }
    
  public void brightenLUT() {
    short brighten[] = new short[256];
    for (int i = 0; i < 256; i++) {
      short pixelValue = (short) (i + 10);
      if (pixelValue > 255)
        pixelValue = 255;
      else if (pixelValue < 0)
        pixelValue = 0;
      brighten[i] = pixelValue;
    }
    lookupTable = new ShortLookupTable(0, brighten);
  }

  public void darkenLUT() {
    short brighten[] = new short[256];
    for (int i = 0; i < 256; i++) {
      short pixelValue = (short) (i - 10);
      if (pixelValue > 255)
        pixelValue = 255;
      else if (pixelValue < 0)
        pixelValue = 0;
      brighten[i] = pixelValue;
    }
    lookupTable = new ShortLookupTable(0, brighten);
  }

  public void contrastIncLUT() {
    short brighten[] = new short[256];
    for (int i = 0; i < 256; i++) {
      short pixelValue = (short) (i * 1.2);
      if (pixelValue > 255)
        pixelValue = 255;
      else if (pixelValue < 0)
        pixelValue = 0;
      brighten[i] = pixelValue;
    }
    lookupTable = new ShortLookupTable(0, brighten);
  }

  public void contrastDecLUT() {
    short brighten[] = new short[256];
    for (int i = 0; i < 256; i++) {
      short pixelValue = (short) (i / 1.2);
      if (pixelValue > 255)
        pixelValue = 255;
      else if (pixelValue < 0)
        pixelValue = 0;
      brighten[i] = pixelValue;
    }
    lookupTable = new ShortLookupTable(0, brighten);
  }

  public void reverseLUT() {
    byte reverse[] = new byte[256];
    for (int i = 0; i < 256; i++) {
      reverse[i] = (byte) (255 - i);
    }
    lookupTable = new ByteLookupTable(0, reverse);
  }
  
  public void reset() {
    big.setColor(Color.black);
    big.clearRect(0, 0, bi.getWidth(this), bi.getHeight(this));
    big.drawImage(displayImage, 0, 0, this);
    bi=biSrc;
    //big2.setColor(Color.black);
    //big2.clearRect(0, 0, bi.getWidth(this), bi.getHeight(this));
    //big2.drawImage(displayImage, 0, 0, this);
  }

  /*public void save(){
        String path="";
        JAI.create("filestore", output, path, "JPEG");
    }
  */
    public void applyFilter() {
    LookupOp lop = new LookupOp(lookupTable, null);
    lop.filter(bi, bi);
  }
    

  public void update(Graphics g) {
    g.clearRect(0, 0, getWidth(), getHeight());
    paintComponent(g);
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage(bi, 0, 0, this);
  }
}

public class editPhoto extends javax.swing.JFrame {
    DisplayPanel1 displayPanel;
    String path;
    JButton brightenButton, darkenButton, contrastIncButton, contrastDecButton, reverseButton, resetButton, blurringButton, sharpenButton, edgeButton;
    photographersMenu PM;
    int num_photo;
    /** Creates new form edit */
    public editPhoto(String path, int num_photo) {
        super();
        this.path = path;
        this.num_photo=num_photo;
        initComponents();
        Container container = getContentPane();
        
        displayPanel = new DisplayPanel1(path);
      
        jPanel2.add(displayPanel);
        jPanel2.setPreferredSize(new Dimension (displayPanel.getWidth(),displayPanel.getHeight()));
        jPanel1.setLayout(new GridLayout(11,8));
        jPanel1.setBorder(new TitledBorder("Click a Button"));

        brightenButton = new JButton("Brightness +");
        brightenButton.addActionListener(new ButtonListener());
        darkenButton = new JButton("Brightness -");
        darkenButton.addActionListener(new ButtonListener());
        contrastIncButton = new JButton("Contrast +");
        contrastIncButton.addActionListener(new ButtonListener());
        contrastDecButton = new JButton("Contrast -");
        contrastDecButton.addActionListener(new ButtonListener());
        reverseButton = new JButton("Negative");
        reverseButton.addActionListener(new ButtonListener());
        blurringButton = new JButton("Blurring");
        blurringButton.addActionListener(new ButtonListener());
        sharpenButton = new JButton("Sharpening");
        sharpenButton.addActionListener(new ButtonListener());
        edgeButton = new JButton("Edge Detect");
        edgeButton.addActionListener(new ButtonListener());
        resetButton = new JButton("Reset");
        resetButton.addActionListener(new ButtonListener());

        jPanel1.add(brightenButton);
        jPanel1.add(darkenButton);
        jPanel1.add(contrastIncButton);
        jPanel1.add(contrastDecButton);
        jPanel1.add(reverseButton);
        jPanel1.add(blurringButton);
        jPanel1.add(sharpenButton);
        jPanel1.add(edgeButton);
        jPanel1.add(resetButton);

        container.add(BorderLayout.SOUTH,jPanel1);
        container.add(BorderLayout.NORTH,jPanel2);
        container.add(BorderLayout.SOUTH,jButton5);
        container.add(BorderLayout.EAST,jButton9);
        container.add(BorderLayout.SOUTH,jTextField1);
        container.add(BorderLayout.SOUTH,jButton1);
        container.add(BorderLayout.SOUTH,jTextField2);
        container.add(BorderLayout.SOUTH,jButton2);
        container.add(BorderLayout.SOUTH,jComboBox1);
        container.add(BorderLayout.SOUTH,jLabel1);
        container.add(BorderLayout.SOUTH,jLabel2);

        this.dispose();
        //T'afegeix una nova finestra i te limita el tamany de la finestra
       /* addWindowListener(new WindowEventHandler());
        setSize(700, displayPanel.getHeight() + 25);
        show();
        */
    }
    /*class WindowEventHandler extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
    }*/
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton5 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("EDIT PHOTO");

        jButton5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton5.setText("Save changes");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 128, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 350, Short.MAX_VALUE)
        );

        jLabel1.setText("Hello,");

        jButton9.setText("logout");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jLabel2.setText("User X");

        jPanel2.setBackground(new java.awt.Color(200, 200, 200));
        jPanel2.setForeground(new java.awt.Color(240, 240, 240));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 421, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 276, Short.MAX_VALUE)
        );

        jButton1.setText("Add Keyword");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Add Taxonomy");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Animales", "Vinos", "Plantas" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 424, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(33, 33, 33)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGap(28, 28, 28))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(27, 27, 27))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)))
                .addComponent(jButton5)
                .addGap(45, 45, 45))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// TODO add your handling code here:
    login log=new login();
    log.setVisible(true);
    this.setVisible(false);
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    //Aqui ha de retornar al photographersMenu el thumbnail de la foto amb el efecte guardat.
    try {
         ImageIO.write(displayPanel.getBi(), "jpg", new File(path));
         //JAI.create("nueva", displayPanel.getBi(), new File(path), "JPEG");
    } catch (IOException e) {
                
    }  
    
    PM = photographersMenu.getPhotographersMenu();
    PM.dispose();
    PM.showPhotos();
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            setKeyword();
        } catch (Exception ex) {
            Logger.getLogger(editPhoto.class.getName()).log(Level.SEVERE, null, ex);
        }
    
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {
            setTaxonomy();
        } catch (Exception ex) {
            Logger.getLogger(editPhoto.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    // TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox1ActionPerformed
public void setTaxonomy(){
        String text = jTextField2.getText();
        String tax = "";
        if (jComboBox1.getSelectedItem().equals("Animales")) tax="animales";
        else if (jComboBox1.getSelectedItem().equals("Vinos")) tax="vinos";
        else if (jComboBox1.getSelectedItem().equals("Plantas")) tax="plantas";
        Object []testArgs = {num_photo,tax, text};
          
        DBManager manager = DBManagerClass.GetInstance();              
        DBActionClass DBact = new DBActionClass("I.insert3",testArgs);
        manager.execute(DBact);
}

public void setKeyword() throws Exception{
        
        String text = jTextField1.getText();
        Object []testArgs = {num_photo, text};
          
        DBManager manager = DBManagerClass.GetInstance();              
        DBActionClass DBact = new DBActionClass("I.insert2",testArgs);
        manager.execute(DBact);
        
   
}
    /**
     * @param args the command line arguments
     */
    

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(editPhoto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(editPhoto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(editPhoto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(editPhoto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //new editPhoto();
        
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new editPhoto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
class ButtonListener implements ActionListener {
    Boolean prova = false;
    public void actionPerformed(ActionEvent e) {
      JButton button = (JButton) e.getSource();

      if (button.equals(brightenButton)) {
        displayPanel.brightenLUT();
        displayPanel.applyFilter();
        displayPanel.repaint();
      } else if (button.equals(darkenButton)) {
        displayPanel.darkenLUT();
        displayPanel.applyFilter();
        displayPanel.repaint();
      } else if (button.equals(contrastIncButton)) {
        displayPanel.contrastIncLUT();
        displayPanel.applyFilter();
        displayPanel.repaint();
      } else if (button.equals(contrastDecButton)) {
        displayPanel.contrastDecLUT();
        displayPanel.applyFilter();
        displayPanel.repaint();
      } else if (button.equals(reverseButton)) {
        displayPanel.reverseLUT();
        displayPanel.applyFilter();
        displayPanel.repaint();
      } else if (button.equals(blurringButton)) {
        displayPanel.blurring();
        displayPanel.repaint(); 
      } else if (button.equals(sharpenButton)) {
        displayPanel.sharpen();
        displayPanel.repaint();
      } else if (button.equals(edgeButton)) {
        displayPanel.edgeDetect();
        displayPanel.repaint();
      } else if (button.equals(resetButton)) {
        displayPanel.reset();
        displayPanel.repaint();
      }
    }
  }
}
